package table;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;

import utils.Utils;


public class InstanceParser {
	public String file_extension;

	private String file_name;

	private EObject root;

	private List<EFactory> factories;
	
	private String uri;
	
	private EPackage pack;
	
	public InstanceParser(EObject root) {
		this.root = root;
		factories = new ArrayList<EFactory>();
	}
	
	public InstanceParser(String file, String extension, String uri, EPackage pack) {
		file_name = file;
		file_extension = extension;
		factories = new ArrayList<EFactory>();
		this.uri = uri;
		this.pack = pack;
	}

	public void save() {
		Utils.saveInstance(file_name, file_extension, root, uri, pack);
	}
	
	void addFactory(EFactory factory) {
		factories.add(factory);
	}
	
	public void setRoot(String type) {
		root = Utils.createObject(type, factories);
	}
	
	public void loadInstance(String file, String ext, EPackage pack) {
		root = Utils.loadInstance(file, ext, pack).getContents().get(0);
	}
	
	public EObject getRoot() {
		return root;
	}
	
	public List<EFactory> getFactories() {
		return factories;
	}	
}
